//===============================================================================
// Microsoft patterns & practices
// Guidance Explorer Offline Client
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================



using GuidanceExplorer.Controls;

namespace GuidanceExplorer.Model
{
    public class ByValueItemMenuCondition : IMenuItemCondition
    {
        #region IMenuItemCondition Members

        public bool ShowMenuItem(MenuItemAttribute attribute, IModelItem modelItem)
        {
            if (modelItem == null)
            {
                return true;
            }
            else
            {
                GuidanceItemNode itemNode = modelItem as GuidanceItemNode;
                GuidanceItemFileReference guidanceItem = itemNode.ModelInstance;
                //TODO:return true if it is a by value container
                if (itemNode != null && guidanceItem.Library != null)
                {
                    return guidanceItem.Library.ReadProtection == ReadProtection.ReadWrite;
                }
                
                return modelItem.IsEditable;
            }
        }

        #endregion
    }
}

